package com.order.web;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.order.dao.bean.Vege;

import java.util.*;

public class VegeServlet extends HttpServlet
{
	public void doGet(HttpServletRequest req,HttpServletResponse resp)
            throws ServletException,IOException
            {
            	doPost(req,resp);
            }

   public void doPost(HttpServletRequest req,HttpServletResponse resp)
             throws ServletException,IOException   
             {
             		resp.setContentType("text/html;charset=gbk");
             		req.setCharacterEncoding("gbk");
                	String action=req.getParameter("test");
                	System.out.print(action);
                	Vege vege=new Vege();
                	if(action.equals("addvege"))
                	{
                		String cvname=req.getParameter("cvname");
                		String cvpy=req.getParameter("cvpy");
                		String cveng=req.getParameter("cveng");
                		String cvno=req.getParameter("cvno");
                		String cvpri=req.getParameter("cvpri");
                		String cvapri=req.getParameter("cvapri");
                		String cvmd=req.getParameter("cvmd");
                		String cvcu=req.getParameter("cvcu");
                		String cvintro=req.getParameter("cvintro");
                		String cvyy=req.getParameter("cvyy");
                		String cvcl=req.getParameter("cvcl");
                		String cvct=req.getParameter("cvct");
                		String cvvt=req.getParameter("cvvt");
                	    vege.addvege(cvname,cvpy,cveng,cvno,cvpri,cvapri,cvmd,cvcu,cvintro,cvyy,cvcl,cvvt,cvct);
                		this.forward("vege.jsp", req, resp);
                	}
                	else if(action.equals("delvege"))
                	{
                		String cvname=req.getParameter("cvname");
                		vege.delvege(cvname);
                		this.forward("vege.jsp", req, resp);
                	}
                	else if(action.equals("searchvege"))
                	{
                		String cvname=req.getParameter("cvname");
                		vege.search(cvname);
                		
                		this.forward("vege.jsp", req, resp);
                		
                	}
                	
             } 
 
   public void forward(String path,HttpServletRequest req,
  HttpServletResponse resp)
throws ServletException,
  IOException
  {
  	req.getRequestDispatcher("/"+path).include(req,resp);
  }            
}